package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class JDBCDemo {
    public static void main(String[] args) throws Exception{

        String name = "张三";
        int age = 0;
        /*注册驱动*/
        Class.forName("com.mysql.cj.jdbc.Driver");
        /*创建链接*/
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root",
                "root");
        System.out.println("连接成功");
        /*获取执行者对象*/
        Statement statement = connection.createStatement();
        /*String sql = " CREATE TABLE user6(\n" +
                "     id INT PRIMARY KEY AUTO_INCREMENT,\n" +
                "     name VARCHAR(32),\n" +
                "     age INT(3)\n" +
                " )\n";*/
        String sql2 = "INSERT INTO user6(name,age) VALUES ('"+name+"',"+age+")";
        /*执行sql*/
        statement.execute(sql2);
        System.out.println("执行成功");
        /*关闭连接*/
        connection.close();

    }
}
